<template>
    <Modal
            v-model="modal"
            :title="title">
        <div v-if='modal'>
            <file-upload p-dir='people' :p-count='info.count' @on-success='bookSuccess' @on-delete='bookDelete'>
                <a class="btn btn-sm btn-success">选择文件</a>
            </file-upload>
        </div>
        <div slot="footer">
            <Button type="ghost" @click='cancel'>取消</Button>
            <btn-submit :p-click='ok'>确定</btn-submit>
        </div>
    </Modal>
</template>
<script>
    const setDataDef = {
        count:1,
        file:[],
    };
    import serCustomer from '../../serves/api-customer'
    export default{
        data () {
            return {
                modal: false,
                info:{},
            }
        },
        computed:{
            title(){
                return '上传更新参会人员文件'
            }
        },
        methods: {
            handleOpen(data){
                this.info = Object.assign({},setDataDef,data);
                this.$set(this,'modal',true);
            },
            bookSuccess(data){
                let arr = [];
                data.fileList.forEach((v)=>{
                    arr.push({
                        "file_alias": v.alias,
                        "file_size": v.size,
                        "file_name": v.name
                    })
                });
                this.$set(this.info,'file',arr);
            },
            bookDelete(data){
                this.info.file.splice(data.index,1);
            },
            async ok () {
                let data = {};
                data.file=this.info.file;
                const res = await serCustomer.importFile(data);
                if(res.code==1){
                    this.$Message.success(res.message);
                    this.$set(this,'modal',false);
                    this.$emit('on-change',true);
                    return true;
                }else{
                    this.$Message.error(res.message);
                    return false;
                }
            },
            cancel () {
                this.$set(this,'modal',false);
                this.$emit('on-change',false);
            },
        },
        components:{
        }
    }
</script>